package com.lp.service.impl;

import com.lp.dao.StudentDao;
import com.lp.po.PagingVO;
import com.lp.po.Student;
import com.lp.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("studentService")
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentDao studentDao;
    /*admin身份控制方法*/
    //返回学生总数
    @Override
    public int getCountStudent() throws Exception {
        return studentDao.count();
    }
    @Override
    public int getCountStudentByName(String username) throws Exception {
        return studentDao.countByName(username);
    }
    @Override
    public List<Student> findAll(Integer toPageNo) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Student> list=studentDao.findAll(pagingVO);
        return list;
    }

    @Override
    public List<Student> findByName(Integer toPageNo,String username) {
        PagingVO pagingVO = new PagingVO();
        pagingVO.setToPageNo(toPageNo);
        List<Student> list=studentDao.findByName(pagingVO.getTopageNo(),pagingVO.getPageSize(),username);
        return list;
    }

    @Override
    public Student findById(Integer userid) {
        Student student=studentDao.findById(userid);
        return student;

    }

    @Override
    public void removeById(Integer userid) throws Exception {
        studentDao.deleteByPrimaryKey(userid);
    }

    @Override
    public void updataById(Integer userid, Student student) throws Exception {
        studentDao.updateByPrimaryKey(student);
    }
    @Override
    public void inset(Student student){
        studentDao.inset(student);
    }
    @Override
    public int findIdByUsername(String username){
        return studentDao.findIdByUsername(username);
    }

    @Override
    public void updateWithPassword(String username, String password) {
        studentDao.updateWithPassword(username,password);
    }

    /*用户身份控制方法*/
    @Override
    public Student findself(String username) {
        return studentDao.findself(username);
    }

    @Override
    public Student selectName(String username) {
        return studentDao.selectName(username);
    }

    /*小程序模块*/
    @Override
    public List<Student> wxfindUserBytelnumber(String telnumber,String password) {
        return studentDao.wxfindUserBytelnumber(telnumber,password);
    }
    @Override
    public List<Student> wxfindUserByusername(String username,String password) {
        return studentDao.wxfindUserByusername(username,password);
    }
    @Override
    public List<Student> wxfindById(Integer userid) {
        List<Student> student=studentDao.wxfindById(userid);
        return student;
    }

    @Override
    public int wxRegisterStudent(String username, String telnumber, String password, Date grade) {
        return studentDao.wxRegisterStudent(username,telnumber,password,grade);
    }

    @Override
    public List<Student> wxfindCollegeNameWithUserid(Integer collegeid) {
        return studentDao.wxfindCollegeNameWithUserid(collegeid);
    }

    @Override
    public int setCollegeBySId(Student student) throws Exception {
        return studentDao.updateByPrimaryKey(student);
    }
}
